import $ from 'jquery'
import 'bootstrap'
import 'bootstrap-select'

import 'bootstrap/dist/css/bootstrap.css'
import 'bootstrap-select/dist/css/bootstrap-select.css'
import 'styles/main.scss'
import 'styles/pages/registration.scss'


const toggleSource = checked => {
  if (checked) {
    $(`[data-target="source:${checked}"]`).removeClass('hide')
    $(`[data-target="source:${!checked}"]`).addClass('hide')
  } else {
    $(`[data-target="source:${checked}"]`).removeClass('hide')
    $(`[data-target="source:${!checked}"]`).addClass('hide')
  }
}

$(document).on('change', '#source', e => {
  toggleSource(e.target.checked)
})

$('.J_exemplar').on('show.bs.modal', e => {
  const relatedTarget = e.relatedTarget
  const source = relatedTarget.getAttribute('data-source')
  if (source) {
    $('.J_example', e.target).attr('src', source)
  } else {
    e.preventDefault()
  }
})
